package cn.powertime.evaluation.web.controller;


import cn.powertime.evaluation.facade.CpsCourseFacade;
import cn.powertime.evaluation.shiro.jwt.TokenUtils;
import cn.powertime.evaluation.vo.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 课程表 前端控制器
 * </p>
 *
 * @author liqi
 * @since 2019-09-23
 */
@RestController
@RequestMapping("/web/cps-course")
@Api(value = "/web/cps-course", tags = "课程接口", produces = MediaType.ALL_VALUE)
public class CpsCourseController extends BaseController  {

    @Autowired
    private CpsCourseFacade cpsCourseFacade;

    @Autowired
    private TokenUtils tokenUtils;

    @ApiOperation(value = "课程分页列表",response = WebRespCourseListVo.class)
    @PostMapping(value = "/list")
    public Object list(@Validated @RequestBody ParamPageVo<WebReqCourseSearchVo> vo, HttpServletRequest request) {
        IPage<WebRespCourseListVo> list = cpsCourseFacade.list(vo,tokenUtils.getUid(request));
        return success(list);
    }

    @ApiOperation(value = "课程列表(全部)",response = WebRespCourseAllListVo.class)
    @PostMapping(value = "/allList")
    public Object allList() {
        List<WebRespCourseAllListVo> list = cpsCourseFacade.allList();
        return success(list);
    }

    @ApiOperation(value = "课程章节列表",response = WebRespChapterListVo.class)
    @PostMapping(value = "/chapterList/{courseId}")
    public Object chapterList(@PathVariable("courseId") @NotNull(message = "课程id不能为空") Long courseId, HttpServletRequest request) {
        List<WebRespChapterListVo> list = cpsCourseFacade.chapterList(courseId,tokenUtils.getUid(request));
       return success(list);
    }

    @ApiOperation(value = "课程资源列表",response = WebRespCourseResourceListVo.class)
    @PostMapping("/courseResourceList")
    public Object courseResourceList(@Validated @RequestBody WebReqResourceVo vo) {
        List<WebRespCourseResourceListVo> list = cpsCourseFacade.courseResourceList(vo);
        return success(list);
    }

    @ApiOperation(value = "学习进度打点")
    @PostMapping("/record")
    public Object record(@Validated @RequestBody WebReqRecordVo vo) {
        boolean b = cpsCourseFacade.record(vo);
        if(b){
            return success("记录成功");
        }
        return error("记录失败");
    }

//    @ApiOperation(value = "课程学习记录列表",response = WebRespCourseRecordListVo.class)
//    @PostMapping(value = "/recordList")
//    public Object recordList(@Validated @RequestBody PageVo vo) {
//        IPage<WebRespCourseRecordListVo> list = cpsCourseFacade.recordList(vo);
//        return success(list);
//    }


}
